package service

import (
	"gitee.com/wao520/obtain_data/cache"
	"gitee.com/wao520/obtain_data/dao"
	"gitee.com/wao520/obtain_data/model"
)

// 得到一篇文章的详情
func GetOneNovels(id uint64) (*model.Novels, error) {
	// novels, errSel := dao.SelectOneNovels(id)
	// return novels, errSel

	//get from bigcache
	novels, err := cache.GetOneNovelsCache(id)
	if err != nil {
		//get from mysql
		novels, errSel := dao.SelectOneNovels(id)
		if errSel != nil {
			return nil, errSel
		} else {
			//set bigcache
			errSet := cache.SetOneNovelsCache(id, novels)
			if errSet != nil {
				return nil, errSet
			} else {
				return novels, errSel
			}
		}
	} else {
		return novels, err
	}
}
